﻿/*
Copyright 2009 Matías Fidemraizer (www.matiasfidemraizer.com).

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

using System;

#region "Custom namespace declarations"
using Comkarl.Architecture.Patterns.MVC.Entities;
#endregion

namespace Comkarl.Architecture.Patterns.MVC.Entities
{
    /// <summary>
    /// An exception thrown in some situation with an action evolved.
    /// </summary>
    /// <typeparam name="TEntityIdentifierName">
    /// The type for the identifier's name.
    /// </typeparam>
    public class ActionException<TEntityIdentifierName> : EntityException<TEntityIdentifierName> 
        where TEntityIdentifierName : IEquatable<TEntityIdentifierName>
    {
        #region "Constructors"
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="id">
        /// The identifier for the custom message to show when this is thrown.
        /// </param>
        /// <param name="currentAction">
        /// The action evolved in the error.
        /// </param>
        /// <param name="innerException">
        /// An optional exception which can be set if some underlying exception has been thrown.
        /// </param>
        public ActionException(string id, Entities.Action<TEntityIdentifierName> currentAction, Exception innerException)
            : base(id, currentAction, innerException)
        {
        }
        #endregion

        #region "Properties"
        /// <summary>
        /// Hides the base CurrentEntity property in order to provide the CurrentAction
        /// counterpart encapsulately casted to Action.
        /// </summary>
        new private string CurrentEntity { get { return null; } }

        /// <summary>
        /// Gets the action evolved in the error.
        /// </summary>
        public Entities.Action<TEntityIdentifierName> CurrentAction
        {
            get
            {
                // Unboxes the base entity because of enforce strong-typing.
                return (Entities.Action<TEntityIdentifierName>)base.CurrentEntity;
            }
        }
        #endregion
    }
}
